package com.zyd.blog.personal.controller;

import com.zyd.blog.business.annotation.BussinessLog;
import com.zyd.blog.business.enums.ResponseStatus;
import com.zyd.blog.framework.object.PageResult;
import com.zyd.blog.framework.object.ResponseVO;
import com.zyd.blog.personal.service.DesignerApplyDealService;
import com.zyd.blog.personal.vo.DesignerApplyInfoConditionVo;
import com.zyd.blog.personal.vo.ReviewResultVo;
import com.zyd.blog.util.ResultUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 设计师申请信息处理
 * @author mfy
 */
@Controller
@RequestMapping("/dealDesignerApply")
public class DesignerApplyDealController {

    @Resource
    private DesignerApplyDealService designerApplyDealService;

    /**
     * 进入设计师用户界面
     * 访问路径 http://localhost:8085/dealDesignerApply
     * @return
     */
    @BussinessLog("设计师申请信息列表界面")
    @RequestMapping("")
    public ModelAndView front() {
        return ResultUtil.view("personal/applyList");
    }

    /**
     * 得到设计师列表
     * 访问路径 http://localhost:8085/dealDesignerApply/list
     * @param designerApplyInfoConditionVo   条件
     * @return  结果
     */
    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(DesignerApplyInfoConditionVo designerApplyInfoConditionVo) {
        List<Map<String,Object>> designers = designerApplyDealService.getDesignerApplyInfo(designerApplyInfoConditionVo);
        return ResultUtil.tablePage((long) designers.size(),designers);
    }

    /**
     * 得到设计师详细申请信息
     * 访问路径 http://localhost:8085/dealDesignerApply/designerDetailPage
     * @return  页面
     */
    @RequestMapping("/designerDetailPage/{id}")
    @ResponseBody
    public ResponseVO designerDetailPage(@PathVariable("id") String id) {
        DesignerApplyInfoConditionVo designerApplyInfoConditionVo = new DesignerApplyInfoConditionVo();
        designerApplyInfoConditionVo.setId(id);
        return ResultUtil.success(null, designerApplyDealService.getDesignerApplyDetailInfo(designerApplyInfoConditionVo));
    }

    /**
     * 删除设计师信息
     * 访问路径 http://localhost:8085/dealDesignerApply/del
     * @param id    申请id
     * @return  页面
     */
    @RequestMapping("/del")
    @ResponseBody
    public ResponseVO del(Long id){
        try {
            designerApplyDealService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error("删除失败！");
        }
        return ResultUtil.success(ResponseStatus.SUCCESS);
    }

    /**
     * 审核设计师申请
     * 访问路径 http://localhost:8085/dealDesignerApply/review
     * @param review    审核结果
     * @return  操作结果
     */
    @RequestMapping("/review")
    @ResponseBody
    public ResponseVO review(ReviewResultVo review){
        String result = "审核不通过";
        if(result.equals(review.getResult())){
            return ResultUtil.success(ResponseStatus.SUCCESS);
        }
        try {
            designerApplyDealService.review(review);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error("删除失败！");
        }
        return ResultUtil.success(ResponseStatus.SUCCESS);
    }

}
